import { Component, Inject } from 'vue-property-decorator';

import { ConfigType, ViewFieldDescriptor, ViewContext } from '../../vendors/handie';

import BaseHeadlessWidget from '../base/Base';

@Component
export default class ViewHeadlessWidget<
  ViewContextType extends ViewContext = ViewContext
> extends BaseHeadlessWidget {
  @Inject({ from: 'viewContext', default: null })
  protected readonly context!: ViewContextType;

  protected loading: boolean = false;

  protected get fields(): ViewFieldDescriptor[] {
    return this.context.getFields();
  }

  protected get config(): ConfigType {
    return this.context.getConfig() || {};
  }

  protected created(): void {
    this.on('busyChange', busy => (this.loading = busy));
  }
}
